#include "stdafx.h"
#include "Graphic_Shader.h"


Graphic_Shader :: Graphic_Shader()
: m_pEffect(NULL)
{
}

Graphic_Shader :: ~Graphic_Shader()
{
	delete m_pEffect;
	m_pEffect = NULL;
}

bool Graphic_Shader :: Initialize(const std::string & FilePath, HGE_Impl * HgeSystem)
{
	HRESULT Hr;
	void * Buffer = Buffer = HgeSystem->Resource_Load(FilePath.c_str());
	std::string Text = static_cast<const char *>(Buffer);
	if(Buffer)
	{
		Hr =	D3DXCreateEffect(	HgeSystem->pD3DDevice,  
									Buffer, static_cast<int>(Text.size()), 
									NULL, NULL, D3DXFX_NOT_CLONEABLE | D3DXSHADER_DEBUG, 
									NULL, &m_pEffect, NULL);
		HgeSystem->Resource_Free(Buffer);
	}
	else
	{		
		Hr =	D3DXCreateEffectFromFileA(HgeSystem->pD3DDevice, 
				FilePath.c_str(), NULL, NULL, 
				D3DXFX_NOT_CLONEABLE | D3DXSHADER_DEBUG, 
				NULL, &m_pEffect, NULL);
	}
	if(FAILED(Hr)) 
	{
		WriteCommandLine("Shader Failed to Create From : %s", FilePath.c_str());	
		return false;
	}
	return true;
}